﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RepositoryAndEf.Core.Data;
using RepositoryAndEf.Core.Common;
using RepositoryAndEf.Infrastructure.Encryption;


namespace RepositoryAndEf.Domain
{
    public class UserService
    {
        private IRepository<User> _userRepository;

        public UserService(IRepository<User> userRepsoitory)
        {
            _userRepository = userRepsoitory;
        }

        public virtual User Register(string email, string name, string password)
        {
            if (_userRepository.Get(u => u.Email == email).Count() != 0)
            {
                throw new ArgumentException("email has already existed");
            }

            var user = new User
            {
                Id = Guid.NewGuid(),
                Email = email,
                Name = name,
                Password = password
            };

            user.CreateShoppingCart();
            _userRepository.Insert(user);
            return user;
        }
    }
}
